<template>
  <div id="app">
    <div v-if="isShow">
      <div class="topBg">
        <div class="topBgImg">
          <img
            src="https://pic1.zhimg.com/v2-e0603518b18c6f6eaa378ad19773fd23_r.jpg"
            alt=""
          />
        </div>
        <div class="topBgtext1">网易云音乐</div>
        <div class="topBgtext2">下载APP</div>
      </div>
      <div class="topPanent">
        <div>
          <router-link to="/">推荐音乐</router-link>
        </div>
        <div>
          <router-link to="/hot">热歌榜</router-link>
        </div>
        <div>
          <router-link to="/search">搜索</router-link>
        </div>
        <router-link to="/billboard"></router-link>
        <router-link to="/geci"></router-link>
      </div>
    </div>
    <router-view
      @change-musics-list="changeMusicsList"
      @billboard-item="billboardItem"
      :billboardList="billboardList"
      :paused="paused"
      :songId="song?.id && song.id"
      :song="song"
      @pause-audio="pauseAudio"
      @play-audio="playAudio"
    />
    <div style="height: 45rem" v-if="isShow"></div>
    <div class="audioParent" @click="addGeci" v-if="isShow">
      <div :class="{ paused: paused }">
        <div>
          <img
            class="audioImg1" 
            :src="(song?.al && song.al.picUrl) || (song?.picUrl && song.picUrl)"
            alt=""
          />
        </div>
        <div class="textsss">
          <span class="name">{{ song?.id && song.name }}</span>
          <span
            class="natu"
            v-for="item in (song?.id && song.ar) ||
            (song?.id && song.song.artists)"
            :key="item.id"
          >
            &nbsp;&nbsp;-&nbsp; {{ item.name }}
          </span>
        </div>
        <div class="boFang">
          <span v-if="paused" @click.stop="playAudio(true)"
            ><img src="./img/boFang.png" alt=""
          /></span>
          <span v-else @click.stop="pauseAudio(false)"
            ><img src="./img/zanTing.png" alt="" />
          </span>
        </div>
        <div>
          <img class="audioImg2" src="./img/24gf-playlistMusic.png" alt="" />
        </div>
      </div>
    </div>
    <audio
      ref="audio"
      @play="paused = false"
      @pause="paused = true"
      :src="
        song?.id &&
        `https://music.163.com/song/media/outer/url?id=${song.id}.mp3`
      "
      controls
      autoplay
    ></audio>
  </div>
</template>
<script>
export default {
  data() {
    return {
      song: null,
      isShow: true,
      billboardList: null,
      paused: true,
    };
  },
  
  watch: {
    $route: {
      handler: function () {
        this.$route.fullPath == "/billboard"
          ? (this.isShow = false)
          : (this.isShow = true);
        this.$route.fullPath == "/geci"
          ? (this.isShow = false)
          : (this.isShow = true);
      },
      // 深度观察监听
      deep: true,
    },
  },
  methods: {
    addGeci() {
      this.$router.push("/geci");
    },
    changeMusicsList(list) {
      this.song = list;
    },
    billboardItem(e) {
      this.billboardList = e;
      this.isShow = false;
    },
    playAudio(s) {
      this.paused=s
      this.$refs.audio.play();
      console.log(111);
      
    },
    pauseAudio(s) {
      this.paused=s
      this.$refs.audio.pause();
      console.log(111);
      
    },
  },
  created() {
    this.$route.name;
    if (this.$route.name == null) {
      this.$router.push("/");
    }
  },
};
</script>
<style lang="scss" scoped>
@keyframes myrotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}
.audioParent {
  position: fixed;
  bottom: 0;
  width: 375rem;
  height: 45rem;
  background-color: rgb(248, 248, 248);
  line-height: 45rem;
  > div {
    position: relative;
    display: flex;
    justify-content: baseline;
    justify-items: center;

    &.paused {
      img.audioImg1 {
        animation-play-state: paused;
      }
    }
    .audioImg1 {
      width: 45rem;
      height: 45rem;
      border: none;
      border-radius: 50%;
      margin-left: 20rem;
      animation: myrotate 8s linear infinite;
    }
    .textsss {
      width: 200rem;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
      .name {
        font-size: 14rem;
        color: #000;
        margin-left: 10px;
      }
      .natu {
        font-size: 14rem;
        color: rgb(110, 107, 107);
      }
    }

    .boFang {
      position: absolute;
      right: 60rem;
      width: 35rem;
      height: 35rem;
      border-radius: 50%;
      text-align: center;
      line-height: 35rem;
      img {
        width: 40rem;
        height: 40rem;
        margin-top: 2rem;
      }
    }
    .audioImg2 {
      width: 35rem;
      height: 35rem;
      position: absolute;
      right: 10rem;
      top: 3rem;
    }
  }
}
audio {
  position: fixed;
  bottom: 0;
  width: 100%;
  display: none;
}
html {
  background-color: #fff;
}
* {
  margin: 0;
  padding: 0;
}
.topBg {
  background-color: rgb(212, 60, 51);
  width: 375rem;
  height: 85rem;
  display: flex;
  line-height: 85rem;
  position: relative;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 375rem;
  overflow: hidden;
  margin: 0 auto;
}
.topBgImg {
  width: 25rem;
  height: 25rem;
  // overflow: hidden;
  margin-top: 7rem;
  margin-left: 20rem;
}
.topBgImg > img {
  width: 25rem;
  height: 25rem;
  border-radius: 12.5rem;
}
.topPanent {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  border-bottom: 1rem solid rgb(218, 214, 214);
  a {
    font-weight: bold;
    color: #2c3e50;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14rem;
    &.router-link-exact-active {
      color: red;
      border-bottom: 3rem solid red;
    }
  }
}
.topPanent > div {
  width: 33%;
  text-align: center;
  height: 40rem;
  line-height: 37rem;
}
.topBgtext1 {
  color: #fff;
  font-size: 16rem;
  margin-left: 5rem;
}
.topBgtext2 {
  background: #ffffff;
  width: 100rem;
  height: 35rem;
  border-radius: 18rem;
  text-align: center;
  line-height: 36rem;
  font-size: 16rem;
  color: red;
  margin-top: 25rem;
  position: absolute;
  right: 20rem;
}
</style>
